package com.yxuan.springboot.service.impl;

import com.yxuan.springboot.mapper.UserVipMapper;
import com.yxuan.springboot.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yxuan.springboot.model.UserVip;
import com.yxuan.springboot.service.UserVipService;

import java.util.List;

/**
 * 
 * @author zchao
 *    UserVip业务层实现类
 * @date 2023-05-09 08:56:34
 */
@Service
@Transactional
public class UserVipServiceImpl extends BaseServiceImpl<UserVip> implements UserVipService {

    @Autowired
    private UserVipMapper userVipMapper;


    @Override
    public Result updateVipByPay(int userId, String goodsName) throws Exception {
        return null;
    }

    /**
     * 微信支付回调成功后更改vip响应数据
     * @param
     * @param
     * @return
     * @throws Exception
     */
//    @Override
//    public Result updateVipByPay(int userId, String goodsName) throws Exception {
//
//        UserVip userVip = new UserVip();
//        userVip.setUserId(userId);
//        UserVip finalUserVip = null;
//
//        //根据购买商品名称修改vip表里相应的会员到期时间等其他字段数据
//
//        //商品名为购买日会员订单
//        if("购买日会员订单".equals(goodsName)){
//            userVip.setVipRank("1");
//            finalUserVip = updVip(userVip,0,0,1,"99999","2","20");
//
//        }
//
//
//        //商品名为购买周会员订单
//        if("购买周会员订单".equals(goodsName)){
//            userVip.setVipRank("2");
//            finalUserVip = updVip(userVip,0,0,7,"99999","3","30");
//
//        }
//
//        //商品名为购买月会员订单
//        if("购买周会员订单".equals(goodsName)){
//            userVip.setVipRank("3");
//            finalUserVip = updVip(userVip,0,1,0,"99999","4","40");
//
//        }
//
//
//
//
//            Integer update = userVipMapper.update(finalUserVip);
//        if(update>0){
//            return new Result(UPDATE_OK,"数据修改成功");
//        }
//
//        return new Result(UPDATE_NO,"数据修改失败");
//    }

    @Override
    public List<UserVip> findAllVips() throws Exception {


        List<UserVip> allVips = userVipMapper.findAllVips();

        return allVips;
    }

    @Override
    public List<UserVip> findAllPoors() throws Exception {
        List<UserVip> allPoors = userVipMapper.findAllPoors();
        return allPoors;
    }


    //重置每个等级会员用户的修改个人信息次数
    @Override
    public Integer updVipUpdInfoNum(Integer userId, int vipRank) throws Exception {

        switch (vipRank){
            case 0:{
                //日会员
                Integer integer = userVipMapper.updVipUpdInfoNum(userId, "1");
                return integer;

            }


            case 1:{
                //日会员
                Integer integer = userVipMapper.updVipUpdInfoNum(userId, "2");
                return integer;

            }
            case 2:{
                //周会员
                Integer integer = userVipMapper.updVipUpdInfoNum(userId, "3");
                return integer;

            }
            case 3:{
                //月会员
                Integer integer = userVipMapper.updVipUpdInfoNum(userId, "5");
                return integer;

            }


        }


        return null;

    }

    @Override
    public List<UserVip> findVipsByCondition(String vipRank) throws Exception {

        List<UserVip> vipsBycondition = userVipMapper.findVipsBycondition(vipRank);


        return vipsBycondition;
    }


//    private UserVip updVip(UserVip userVip,int year,int month,int day,String probabilityTimes,String infoUpdTimes,String gptTimes) throws ParseException {
//        //设置会员到期时间
//        Date date = DaysCalculateUtil.targetDate(new Date(), year, month, day);
//        userVip.setExpirationTime(date);
//        userVip.setFillingTimes("50");
//        userVip.setCourseSelectionTimes("50");
//        userVip.setProbabilityTimes(probabilityTimes);
//        userVip.setInfoUpdTimes(infoUpdTimes);
//        userVip.setGptTimes(gptTimes);
//        return userVip;
//    }


}
